#ifndef NPC_H
#define NPC_H

#include "Character.h"
#include <QRandomGenerator>
#include <QRectF>
#include "MapManager.h"
#include"GlobalObject.h"

class NPC : public Character
{
    Q_OBJECT
public:
    enum class BehaviorType{
        StaticNpc,
        Wandering
    };

    explicit NPC(MapManager *mapManager, QObject *parent = nullptr);

    // 设置NPC行为
    void setBehaviorType(BehaviorType type) { m_npcStatus = type; }

    void setMovementArea(const QRectF& area) { m_movementArea = area; }

    // 更新NPC行为
    void update(float deltaTime) override;

    QVector<Pokemon *> npcPokemon;
    bool isPokemonBattle();
protected:
    void initializeCollisionShape() override; // 初始化碰撞形状（重写基类实现）
private:
    void updateWandering(float deltaTime); // 针对Wandering类型NPC的更新

    bool checkTerrainCollision(const QPointF &newPos) const;   // 地形碰撞检测
    QPointF findSafePosition(const QPointF &desiredPos) const; // 寻找安全位置

    BehaviorType m_npcStatus; // npc的状态
    QRectF m_movementArea;
    Direction m_npcDirection = DIR_DOWN;
    MapManager *m_mapManager;

    float m_directionTimer = 0.0f;
    const float DIRECTION_CHANGE_INTERVAL = 2.0f; // 每2秒改变一次方向
};

#endif // NPC_H
